home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / qed / src / global.c < prev    next >
C/C++ Source or Header  |  1998-10-19  |  9KB  |  410 lines

  1. #include <stdarg.h>
  2. #include <stat.h>
  3. #include <support.h>
  4. #include <time.h>
  5. #include <unistd.h>
  6.  
  7. #include "global.h"
  8. #include "makro.h"
  9. #include "options.h"
  10. #include "rsc.h"
  11. #include "set.h"
  12. #include "window.h"
  13.  
  14.  
  15. /*
  16.  * exportierte Variablen
  17.  */
  18. int        fill_color;            /* aktuell eingestellte Füllfarbe */
  19. int        planes;                /* Anzahl der Planes */
  20.  
  21. bool        quick_close;        /* Sichern der Texte ohne Nachfrage */
  22. int        vdi_handle;            /* Virtuelles Workstation Handle */
  23.  
  24. bool        done;                    /* Ende gewählt ? */
  25.  
  26. int        desire_x, return_code;
  27. long        desire_y, undo_y;
  28.  
  29. int        font_id, font_pts, 
  30.             font_wcell, font_hcell,
  31.             min_ascii, max_ascii;
  32. bool        font_prop;
  33.  
  34. int        debug_level;
  35.  
  36. /****** lokale Variablen *****************************************************/
  37.  
  38. static bool     msleep = FALSE;
  39.  
  40. static GRECT     clip;             /* Letztes Clipping Rechteck */
  41. static bool     clip_flag;
  42.  
  43. static long        _idt;                /* Cookie für Datum und Zeit */
  44.  
  45. /*****************************************************************************/
  46. /* Maus-Routinen                                                                                                                         */
  47. /*****************************************************************************/
  48. bool mouse_sleeps(void)
  49. {
  50.     return msleep;
  51. }
  52.  
  53. void sleep_mouse(void)
  54. {
  55.     if (!msleep)
  56.     {
  57.         msleep = TRUE;
  58.         hide_mouse();
  59.     }
  60. }
  61.  
  62. void wake_mouse(void)
  63. {
  64.     if (msleep)
  65.     {
  66.         msleep = FALSE;
  67.         show_mouse();
  68.     }
  69. }
  70.  
  71. /*****************************************************************************/
  72. /* Ausgabe recht oben im Menü */
  73. void print_headline(char *str)
  74. {
  75.     GRECT    c;
  76.         
  77.     if (gl_desk.g_y != 1)        /* gl_desk.g_y = 1: Menü unsichtbar unter N.AES */
  78.     {
  79.         if (str[0] == EOS)        /* löschen */
  80.             menu_bar(menu, 1);
  81.         else
  82.         {
  83.             int     d;
  84.             int    pxy[8];
  85.             
  86.             get_clip(&c);
  87.             set_clip(FALSE, NULL);
  88.             vst_font(vdi_handle, sys_big_id);
  89.             vst_height(vdi_handle, sys_big_height, &d, &d, &d, &d);
  90.             vqt_extent(vdi_handle, str, pxy);
  91.             vswr_mode(vdi_handle, MD_TRANS);
  92.             v_gtext(vdi_handle, gl_desk.g_x + gl_desk.g_w - (pxy[2] - pxy[0]) - 20, 0, str);
  93.             vswr_mode(vdi_handle, MD_REPLACE);
  94.             vst_font(vdi_handle, font_id);
  95.             vst_point(vdi_handle, font_pts, &d, &d, &d, &d);
  96.             set_clip(TRUE, &c);
  97.         }
  98.     }
  99. }
  100.  
  101. /*****************************************************************************/
  102. bool shift_pressed(void)
  103. {
  104.     int    d, kstate;
  105.  
  106.     if (makro_play)
  107.         kstate = makro_shift;
  108.     else
  109.         graf_mkstate(&d, &d, &d, &kstate);
  110.     return ((kstate & (K_LSHIFT|K_RSHIFT)) != 0);
  111. }
  112.  
  113. /*****************************************************************************/
  114. bool inside (int x, int y, GRECT *r)
  115. {
  116.     return (x >= r->g_x && y >= r->g_y && x < r->g_x + r->g_w && y < r->g_y + r->g_h);
  117. }
  118.  
  119. /*****************************************************************************/
  120. bool get_clip (GRECT *size)
  121. {
  122.     *size = clip;
  123.     return clip_flag;
  124. }
  125.  
  126. void set_clip (bool clipflag, GRECT *size)
  127. {
  128.     int    xy[4];
  129.  
  130.     if (!clip_flag && !clipflag) 
  131.         return;                                        /* Es ist aus und bleibt aus */
  132.     clip_flag = clipflag;
  133.     if (clipflag)
  134.     {
  135.         if (size == NULL)
  136.             clip = gl_desk;                        /* Nichts definiert, nimm Desktop */
  137.         else
  138.             clip = *size;                            /* Benutze definierte Größe */
  139.         xy[0] = clip.g_x;
  140.         xy[1] = clip.g_y;
  141.         xy[2] = xy[0] + clip.g_w - 1;
  142.         xy[3] = xy[1] + clip.g_h - 1;
  143.     }
  144.     else
  145.         clip = gl_desk;
  146.     vs_clip (vdi_handle, clipflag, xy);
  147. }
  148.  
  149.  
  150. /*****************************************************************************/
  151.  
  152. static int do_note(int def, int undo, char *s)
  153. {
  154.     wake_mouse();
  155.     return do_walert(def, undo, s, " qed ");
  156. }
  157.  
  158. int note(int def, int undo, int index)
  159. {
  160.     return do_note(def, undo, (char *)alertmsg[index]);
  161. }
  162.  
  163. int inote(int def, int undo, int index, int val)
  164. {
  165.     char    buf[128];
  166.     
  167.     sprintf(buf, (char *)alertmsg[index], val);
  168.     return do_note(def, undo, buf);
  169. }
  170.  
  171. int snote(int def, int undo, int index, char *val)
  172. {
  173.     char    buf[128];
  174.     
  175.     sprintf(buf, (char *)alertmsg[index], val);
  176.     return do_note(def, undo, buf);
  177. }
  178.  
  179. /***************************************************************************/
  180. /* Verschiedenes                                                                                */
  181. /***************************************************************************/
  182.  
  183. void file_name(char *fullname, char *filename, bool withoutExt)
  184. {
  185.     split_filename(fullname, NULL, filename);
  186.     if (withoutExt)
  187.     {
  188.         char    *p;
  189.  
  190.         p = strrchr(filename, '.');
  191.         if (p != NULL)
  192.             *p = EOS;
  193.     }
  194. }
  195.  
  196. /*****************************************************************************/
  197.  
  198. static void make_date(struct tm *stime, char *date)
  199. {
  200.     if (date != NULL)
  201.     {
  202.         switch ((unsigned int)_idt & 0xF00)            /* Reihenfolge im Datum */
  203.         {
  204.             case 0x000:  /* MM/DD/YYYY */
  205.                 strftime(date, 11, "%m/%d/%Y", stime);
  206.                 break;
  207.             case 0x100:  /* DD.MM.YYYY */
  208.                 strftime(date, 11, "%d.%m.%Y", stime);
  209.                 break;
  210.             default:  /* YYYY-MM-DD */
  211.                 strftime(date, 11, "%Y-%m-%d", stime);
  212.                 break;
  213.         }
  214.     }
  215. }
  216. /*****************************************************************************/
  217.  
  218. void get_datum(char *date)
  219. {
  220.     time_t        ttime;
  221.     struct tm    *stime;
  222.  
  223.     time(&ttime);
  224.     stime = localtime(&ttime);
  225.     make_date(stime, date);
  226. }
  227.  
  228. /*****************************************************************************/
  229.  
  230. long file_time(char *filename, char *date, char *time)
  231. {
  232.     struct stat    s;
  233.  
  234.     if (stat(filename, &s) == 0)
  235.     {
  236.         struct tm    *stime;
  237.  
  238.         stime = localtime(&s.st_mtime);
  239.         if (time != NULL)
  240.             strftime(time, 9, "%H:%M:%S", stime);
  241.         if (date != NULL)
  242.             make_date(stime, date);
  243.         return s.st_mtime;
  244.     }
  245.     else
  246.     {
  247.         if (time != NULL)
  248.             strcpy(time, "??");
  249.         if (date != NULL)
  250.             strcpy(date, "??");
  251.         return 0;
  252.     }
  253. }
  254.  
  255. /*****************************************************************************/
  256. long file_size(char *filename)
  257. {
  258.     struct stat    s;
  259.     
  260.     if (stat(filename, &s) == 0)
  261.         return s.st_size;
  262.     else
  263.         return 0;
  264. }
  265.  
  266. /*****************************************************************************/
  267. bool file_readonly (char *filename)
  268. {
  269.     struct stat    s;
  270.     bool        ret = FALSE;
  271.     
  272.     if (stat(filename, &s) == 0)
  273.     {
  274.         int    uid, gid;
  275.  
  276.         uid = getuid();
  277.         gid = getgid();
  278.         if (((uid == s.st_uid) && ((s.st_mode & S_IWUSR) != 0)) ||    
  279.                 /* Besitzer hat Schreibrecht */
  280.            
  281.                ((gid == s.st_gid) && ((s.st_mode & S_IWGRP) != 0)) ||    
  282.                    /* Gruppe hat Schreibrecht */
  283.             
  284.             (((s.st_mode & S_IWOTH) != 0))    ||                                
  285.                 /* Welt hat Schreibrecht */
  286.             
  287.             ((uid == 0) && ((s.st_mode & S_IWUSR) != 0)))                
  288.                 /* root darf, wenn Owner darf */
  289.             ret = FALSE;
  290.         else
  291.             ret = TRUE;
  292.     }
  293.     return ret;
  294. }
  295.  
  296.  
  297. /***************************************************************************/
  298. bool path_from_env(char *env, char *path)
  299. {
  300.     char    *p;
  301.     bool    ret = FALSE;
  302.         
  303.     p = getenv(env);
  304.     if (p != NULL)
  305.     {
  306.         strcpy(path, p);
  307.         ret = make_normalpath(path);
  308. /*
  309.         i = (int)strlen(path);
  310.         if (p[i-1] != '\\')
  311.             strcat(path, "\\");
  312. */
  313.     }
  314.     return ret;
  315. }
  316.  
  317. /***************************************************************************/
  318. bool is_bin_name(char *filename)
  319. {
  320.     char    *p;
  321.     int    i;
  322.     
  323.     p = strrchr(filename, '.');
  324.     if (p != NULL)
  325.     {
  326.         for (i = 0; i < BIN_ANZ; i++)
  327.         {
  328.             if (stricmp(p+1, bin_extension[i]) == 0)
  329.                 return TRUE;
  330.         }
  331.     }
  332.     return FALSE;
  333. }
  334.  
  335. /***************************************************************************/
  336. void font_change(void)
  337. {
  338.     int    ret, w1, w2, d, d1[5], d2[3];
  339.  
  340.     /* *_cell werden NUR hier verändert */
  341.     vst_font(vdi_handle, font_id);
  342.     font_pts = vst_point(vdi_handle, font_pts, &d, &d, 
  343.                                         &font_wcell, &font_hcell);
  344.  
  345.     vqt_width(vdi_handle, 'M', &w1, &ret, &ret);
  346.     vqt_width(vdi_handle, 'i', &w2, &ret, &ret);
  347.     font_prop = (w1 != w2);
  348.  
  349.     vqt_fontinfo(vdi_handle, &min_ascii, &max_ascii, d1, &d, d2);
  350.     if (min_ascii <= 0)
  351.         min_ascii = 1;
  352.  
  353.     /* Alle Fenster updaten */
  354.     do_all_window(CLASS_ALL, do_font_change);
  355. }
  356.  
  357. void select_font(void)
  358. {
  359.     int    n_id, n_pts;
  360.     bool    ok = FALSE;
  361.  
  362.     n_id = font_id;
  363.     n_pts = font_pts;
  364.     ok = do_fontsel(FS_M_ALL, rsc_string(SELWFONTSTR), &n_id, &n_pts);
  365.     if (ok)
  366.     {
  367.         font_id = n_id;
  368.         font_pts = n_pts;
  369.         font_change();
  370.     }
  371.     else if (n_id == -1 && n_pts == -1)
  372.         note(1, 0, NOFSL);
  373. }
  374.  
  375. /***************************************************************************/
  376. /* Initialisieren des Moduls                                                                */
  377. /***************************************************************************/
  378. void init_global (void)
  379. {
  380.     int    work_out[57];
  381.     int    ret, f_anz;
  382.  
  383.     done = FALSE;
  384.     clip_flag = TRUE;
  385.  
  386.     vdi_handle = open_vwork(work_out);
  387.     f_anz = work_out[10];
  388.     vq_extnd(vdi_handle, TRUE, work_out);
  389.     planes = work_out[4];
  390.  
  391.     if (gl_gdos)
  392.         f_anz += vst_load_fonts(vdi_handle, 0);
  393.  
  394.     vswr_mode(vdi_handle, MD_TRANS);
  395.     vst_alignment(vdi_handle, TA_LEFT, TA_TOP, &ret, &ret);
  396.  
  397.     if (!getcookie("_IDT", &_idt))                /* Format für Datum und Zeit */
  398.         _idt = 0x0000112E;                            /* DD.MM.YYYY HH:MM:SS */
  399. }
  400.  
  401. /************************************************************************/
  402. /* Terminieren des Moduls                                                                */
  403. /************************************************************************/
  404. void term_global(void)
  405. {
  406.     if (gl_gdos)
  407.         vst_unload_fonts(vdi_handle, 0);
  408.     v_clsvwk(vdi_handle);
  409. }
  410.